import { ExecutionContext, Injectable } from '@nestjs/common'
import { Reflector } from '@nestjs/core'
import { AuthGuard } from '@nestjs/passport'

@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {
  constructor(private reflector: Reflector) {
    super()
  }

  canActivate(context: ExecutionContext) {
    // 检查方法级别和控制器级别的元数据
    const skipAuth = this.reflector.getAllAndOverride<boolean>(
      'skip-decorator',
      [context.getHandler(), context.getClass()],
    )

    if (skipAuth) return true // 跳过验证
    // 正常验证逻辑
    return super.canActivate(context)
  }
}
